<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Models\Question;
use App\Models\Answer;
class UserController extends CommonController
{


    /**
     * 个人中心
     *
     * @return \Illuminate\Http\Response
     */
    public function question()
    {

        // 获取Id
        $uid = session('login');
        $question = DB::table('zy_question')->where('uid',$uid)->OrderBy('q_time','desc')->paginate(3);
        // $data = [];
        // foreach ($question as $k=>$v)
        // {
        //     $qid = $v['id'];
        //     $tag = Question::find($qid)->tag()->get();
        //     $data[] = $tag;
        // }
        return view('home.user.question',compact('question'));
    }

    /**
     * 个人中心--我的回答
     *
     * @return \Illuminate\Http\Response
     */
    public function answer()
    {
         $id = session('login');
        // 获取Id
        $uid = session('login');

        $answer = DB::table('zy_answer')->where('uid',$uid)->OrderBy('a_time','desc')->paginate(3);
        $arr = [];
        foreach($answer as $k=>$v)
        {
            // 获取问题的id
            $qid = $v['qid'];
            //获取该问题的信息
            $question = DB::table('zy_question')->where('id',$qid)->get();
            //遍历获取问题标题
            foreach($question as $kk=>$vv)
            {
                $v['q_title'] = $vv['q_title'];

                $arr[] = $v;
            }
        }
        return view('home.user.answer',compact('arr','answer'));
    }

    /**
     * 个人中心--成长与徽章
     *
     * @return \Illuminate\Http\Response
     */
    public function grow()
    {
        $uid=session('login');
        //查询积分表
        $data=DB::table('zy_score')->where('uid',$uid)->first();
        $arr='';
        $arr1='';
       if($data['exp']<=10){
            $arr='2%';
            $arr1='1级';
       }else if($data['exp']>10 && $data['exp']<=50){
            $arr='25%';
            $arr1='2级';
       }else if($data['exp']>50 && $data['exp']<=100){
            $arr='50%';
            $arr1='3级';

       }else if($data['exp']>100 && $data['exp']<=200){
            $arr='63%';
            $arr1='4级';
       }else if($data['exp']>200 && $data['exp']<=500){
            $arr='75%';
            $arr1='5级';
       }else if($data['exp']>500 && $data['exp']<=1000){
            $arr='83%';
            $arr1='6级';
       }else if($data['exp']>1000){
            $arr='100%';
            $arr1='7级';
       }

        // 加载个人中心
        return view('home.user.grow',compact('arr','arr1'));
    }

    /**
     * 个人中心--修改设置
     *
     * @return \Illuminate\Http\Response
     */
    public function modify()
    {
        // 加载个人中心
        return view('home.user.modify');
    }



}
